#include <stdio.h>

#define TRACE(x...) 
#define PRINT(x...) TRACE(printf(x))

#define MULT_TEST(x...) 

int dd, mm, yy;
int bd, bm, by;
int test;

int validDate(int d, int m, int y) {
	if (m<1 || m>12) return 0;
	if (y<1 || y>99) return 0;

	if (d>31) return 0;
	if ((m==4 || m==6 || m==9 || m==11) && (d>30)) return 0; 
	if (m==2 && y%4==0 && d>29) return 0;
	if (m==2 && d>28 && y%4!=0) return 0;

	return 1;
}

int yearsOld(int d, int m, int y) {
	if (y>yy) return -1;
	if (yy-y!=18) return yy-y;

	if (yy%4!=0 && (m==2) && (d==29)) {
		m=3; d=1;
	}

	if (mm>m) return 18;
	if (mm<m) return 17;

	if (dd>=d) return 18;

	return 17; 
}

int perm[3];
int fl;
int yo;

int main() {
	MULT_TEST( 
		scanf("%d", &test);

		while (test--) {
	)

	scanf("%d.%d.%d", &dd, &mm, &yy);
	scanf("%d.%d.%d", &bd, &bm, &by);

	PRINT("cdate: %d %d %d\n", dd, mm, yy);
	PRINT("bdate: %d %d %d\n", bd, bm, by);

	perm[0]=bd; perm[1]=bm; perm[2]=by;
	fl=0;

	for (int i=0; i<3; i++) {
		for (int j=0; j<3; j++) {
			if (i==j) continue;

			for (int k=0; k<3; k++) {
				if (k==j || k==i) continue; 

				PRINT("%d %d %d\n", perm[i], perm[j], perm[k]); 
				if (!validDate(perm[i], perm[j], perm[k])) continue;

				yo=yearsOld(perm[i], perm[j], perm[k]);
				PRINT("%d\n", yo);				

				if (yo>=18) {
					fl=1;
					break;
				}
			}

			if (fl) break;
		}
		
		if (fl) break;		 
	}
	
	if (fl) printf("YES\n");
	else printf("NO\n");

	MULT_TEST( } );

	return 0;
}
